var open = document.getElementById("open");
var close = document.getElementById("close");

open.addEventListener("tap", function() {
	$(this).css('opacity', '0')
	$('.choose').css('height', '30px')
	setTimeout(function() {
		$('.item').css('width', '25%')
		$(this).css('opacity', '0')
		$('.hideclass').css('display', 'block')
	}, 400)
});
close.addEventListener("tap", function() {
	$(this).css('opacity', '1')

	$('.choose').css('height', '0')
	$('.hideclass').css('display', 'none');
	$('.item').css('width', '23%')

	setTimeout(function() {
		$('.open').css('opacity', '1')
	}, 300)
});

AjaxNoLPostFn('api/catalog/selectcatalog', {
	'parentsId': '0'
}, function(jsondata) {
	//查询分类接口

	var str = ''; //下面的分类标题
	var strtop = ''; //上面的分类
	$(".productbox").empty();
	$(".Bigpbox").empty();
	$.each(jsondata.dataResultList, function(idx, obj) {
		//标题
		str += '<p class="title catalogtitle" data-id="' + obj.catalogId + '" >' + obj.nodeName + '</p>' +
			'<div class="productlist">' +
			'</div>';

		//上面的分类
		strtop = '';
		strtop += '<div class="item " style="width: 23%;" " onclick="window.location.href=\'search-page.html?catalogId=' + obj.catalogId + '&title=' + obj.nodeName + '\'">' +
			'<div class="class_img" style="background:url(' + IMGUrl + '' + obj.classifyImage + ') no-repeat center center;"></div>' +
			'<span class="class_text">' + obj.nodeName + '</span>' +
			'</div>'
		if(idx < 4) {
			$(".prolist").append(strtop)
		} else {
			$(".hideclass").append(strtop)
		}

	});
	$(".Bigpbox").html(str);
	$(".catalogtitle").on("tap", function() {
		window.location.href = 'search-page.html?catalogId=' + $(this).attr('data-id') + '&title=' + $(this).text();
	})

	for(i = 0; i < $(".Bigpbox p.catalogtitle").length; i++) {
		(function() {
			//			console.log(i);
			var catalogId = $(".Bigpbox p.catalogtitle").eq(i).attr("data-id");
			AjaxNoLPostFn('api/bizrelatives/selectcmmybyparents?page=2&pagesize=6', {
				'tosort': 'asc',
				'sorting': 'present_price',
				'catalogId': catalogId
			}, function(data, idx) {
				var childstr = '';
				if(data.pageInfo.size != 0) {
					$.each(data.pageInfo.list, function(index, oneItem) {
						childstr += '<div class="mui-col-xs-4 product_img"  style="background-image: url(' + IMGUrl + '' + oneItem.mainPhoto + ');" data-cNum="' + oneItem.commodityNumber + '"><p>' + oneItem.shortName + '</p></div>';
					})

					$(".productlist").eq(idx).html(childstr);
					$(".product_img").on("tap", function() {
						window.top.location.href = 'ProductDetail.html?commodityNumber=' + $(this).attr("data-cNum");
					})
				} else {

				}

			}, i);
		})(i)
	}

	//需要重新导入一边第一个分类下的产品

	AjaxNoLPostFn('api/bizrelatives/selectcmmybyparents?page=2&pagesize=6', {
		'tosort': 'asc',
		'sorting': 'present_price',
		'catalogId': $(".Bigpbox p.catalogtitle").eq(0).attr("data-id")
	}, function(data) {
		var childstr = '';
		if(data.pageInfo.size != 0) {
			$.each(data.pageInfo.list, function(index, oneItem) {
				childstr += '<div class="mui-col-xs-4 product_img"  style="background-image: url(' + IMGUrl + '' + oneItem.mainPhoto + ');" data-cNum="' + oneItem.commodityNumber + '"><p>' + oneItem.shortName + '</p></div>';
			})

			$(".productlist").eq(0).html(childstr);
			$(".product_img").on("tap", function() {
				window.top.location.href = 'ProductDetail.html?commodityNumber=' + $(this).attr("data-cNum");
			})
		} else {

		}

	});

})